package io.task.cc.message.socket.spi.client;

import io.task.cc.message.socket.ChannelContext;
import io.task.cc.message.socket.Config;
import io.task.cc.message.socket.lock.SetWithLock;
import io.task.cc.message.socket.spi.client.intf.ClientHandler;
import io.task.cc.message.socket.task.Handler;
import io.task.cc.message.socket.thread.pool.SynThreadPoolExecutor;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.HashSet;
import java.util.concurrent.ThreadPoolExecutor;

@Slf4j
@Setter
@Getter
public class ClientConfig extends Config {

    private ClientHandler tioClientHandler = null;


    protected ReconnConf reconnConf;//重连配置

    private ConnectionCompletionHandler connectionCompletionHandler = new ConnectionCompletionHandler();

    public final SetWithLock<ChannelContext> connecteds = new SetWithLock<ChannelContext>(new HashSet<ChannelContext>());
    public final SetWithLock<ChannelContext> closeds = new SetWithLock<ChannelContext>(new HashSet<ChannelContext>());

    /**
     * 不重连
     */
    public ClientConfig(ClientHandler tioHandler) {
        this(tioHandler, null);
    }

    /**
     * @param reconnConf 不用框架自动重连，就传null
     */
    public ClientConfig(ClientHandler tioHandler, ReconnConf reconnConf) {
        this(tioHandler, reconnConf, null, null);
    }

    /**
     * @param tioHandler
     * @param reconnConf    不用框架自动重连，就传null
     * @param tioExecutor
     * @param groupExecutor
     */
    public ClientConfig(ClientHandler tioHandler, ReconnConf reconnConf, SynThreadPoolExecutor tioExecutor,
                        ThreadPoolExecutor groupExecutor) {
        super(tioExecutor, groupExecutor);

        this.setTioClientHandler(tioHandler);


        this.reconnConf = reconnConf;
    }


    @Override
    public Handler getTioHandler() {
        return this.getTioClientHandler();
    }


    @Override
    public boolean isServer() {
        return false;
    }

}
